package com.zhouyusunquan.observer.jdk;

import java.util.Observable;
import java.util.Observer;
 
public class CurrentConditionsDisplay implements Observer{
	
	private Observable observable;
	
	private float temperature;
	
	private float pressure;
	
	private float humidity;
	
	public CurrentConditionsDisplay(Observable observable){
		this.observable = observable;
		this.observable.addObserver(this);
	}
 
	public void update(Observable observable, Object obj) {
		if(observable instanceof WeatherData){
			WeatherData weatherData = (WeatherData)observable;
			this.temperature = weatherData.getTemperature();
			this.humidity = weatherData.getHumidity();
			this.pressure = weatherData.getPressure();
			display();
		}
	}
 
	public void display() {
		System.out.println("当前温度:" + this.temperature);
		System.out.println("当期湿度:" + this.humidity);
		System.out.println("当期气压:" + this.pressure);
	}
 
}
